﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sita.Entities;
using Sita.Data.Repositories;

namespace Sita.MainModule.Services
{
    public class ReplacementService
    {
        ReplacementRepository ReplacementRepository;

        public ReplacementService()
        {
            ReplacementRepository = new ReplacementRepository();
        }

        public IList<Replacement> GetAllReplacements()
        {
            return ReplacementRepository.GetAll().ToList();
        }

        public IList<Replacement> GetPaginatedReplacementsByBussinesUnitID(int businessUnitID, int pageIndex, int pageSize, string sortColumn, bool ascending, out int totalRows)
        {
            return ReplacementRepository.GetPaginatedByBusinessUnitID(businessUnitID, pageIndex, pageSize, sortColumn, ascending, out totalRows);
        }

        public IList<Replacement> GetPaginatedByFilter(int businessUnitID, int pageIndex, int pageSize, string sortColumn, bool ascending, string ShelfLocation,
            string RowLocation, string ColumnLocation, string Name, string Code, int ReplacementBrandID, int StockFrom, int StockTo, int MinimumStock, decimal PublicPriceFrom,
            decimal PublicPriceTo, out int totalRows)
        {
            return ReplacementRepository.GetPaginatedByFilter(businessUnitID, pageIndex, pageSize, sortColumn, ascending, ShelfLocation, RowLocation, ColumnLocation, Name, Code, ReplacementBrandID, StockFrom, StockTo, MinimumStock, PublicPriceFrom, PublicPriceTo, out totalRows);
        }

        public int AddReplacement(Replacement replacement)
        {
            ReplacementRepository.Add(replacement);

            ReplacementRepository.StoreContext.Commit();

            return replacement.ReplacementID;
        }

        public Replacement GetReplacementByIDWithWO(int replacementID)
        {
            return ReplacementRepository.GetByIDWithWO(replacementID);
        }

        public Replacement GetReplacementByID(int replacementID)
        {
            return ReplacementRepository.GetByID(replacementID);
        }

        public bool ModifyReplacement(Replacement replacement)
        {
            ReplacementRepository.Modify(replacement);

            ReplacementRepository.StoreContext.Commit();

            return true;
        }

        public bool DeleteReplacement(Replacement replacement)
        {
            ReplacementRepository.Delete(replacement);

            ReplacementRepository.StoreContext.Commit();

            return true;
        }

        public IList<Replacement> GetByBusinessUnitIDByFilter(int businessUnitID, string filter)
        {
            return ReplacementRepository.GetByBusinessUnitIDByFilter(businessUnitID, filter);
        }

        public IList<Replacement> GetLowStockReplacements(int businessUnitID)
        {
            return ReplacementRepository.GetLowStockReplacements(businessUnitID);
        }

        public IList<Replacement> GetOutOfStockReplacements(int businessUnitID)
        {
            return ReplacementRepository.GetOutOfStockReplacements(businessUnitID);
        }
    }
}
